package org.wattdepot.cli;

import org.junit.Before;
import org.junit.Test;
import org.wattdepot.client.BadXmlException;
import org.wattdepot.client.MiscClientException;
import org.wattdepot.client.NotAuthorizedException;
import org.wattdepot.client.WattDepotClient;
import org.wattdepot.resource.source.jaxb.Source;

/**
 * Tests the total power by fuel type command.
 * 
 * @author Aaron Herres
 * 
 */
public class TestTotalPower {
  CommandLineInterface cli;

  /**
   * Initialises class for testing.
   */
  @Before
  public void initializeCommandLineInterface() {
    cli = new CommandLineInterface("http://server.wattdepot.org:8182/wattdepot/");
  }
  /**
   * Tests the total power for fuel types without the user interface frontend.
   */
  @Test
  public void testTotalPower() {
    // difficult to test in this case, as all the sources are virtual.
    WattDepotClient client = cli.getClient();
    TotalPower tp = new TotalPower();
    try {
      String command[] =
          "totalpower SIM_IPP 2009-10-26T18:15:00.000-10:00 fueltype waste".split(" ");
      for (Source s : client.getSources()) {
        command[1] = s.getName();
        String ret = tp.processCommand(client, command);
        System.out.println(s.getName());
        System.out.println(ret);
      }
    }
    catch (NotAuthorizedException e) {
      e.printStackTrace();
    }
    catch (BadXmlException e) {
      e.printStackTrace();
    }
    catch (MiscClientException e) {
      e.printStackTrace();
    }
  }
}
